﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using CustomsSystem.BLL;
using Maticsoft.Common;
using CustomsSystem.Model;

namespace WEB.T_bill
{
    public partial class cost : System.Web.UI.Page
    {
        CustomsSystem.BLL.PayManage payBll = new PayManage();

        protected void Page_Load(object sender, EventArgs e)
        {
            //基础信息绑定
            if (Session["sheetID"] != null && Session["sheetID"].ToString() != "")
            {
                infoBind_Rec();
                infoBind_Pay();
            }
            string a = lbsheetID.Text;
            
            if (!IsPostBack)
            {
                //应收模版
                ddlreceivables.DataSource = GetTemplate();
                ddlreceivables.DataTextField = "templetName";
                ddlreceivables.DataValueField = "ID";
                ddlreceivables.DataBind();

                if (lbsheetID.Text != "" && lbsheetID.Text != null)
                {
                    GetInfo_Rec(int.Parse(a), 1);//制单人信息
                }
                if (gvReceivables.Rows.Count < 1)
                { Bind_Rec(); }

                //应付模版
                ddlPayment.DataSource = GetTemplate_Pay();
                ddlPayment.DataTextField = "templetName";
                ddlPayment.DataValueField = "ID";
                ddlPayment.DataBind();
                if (lbsheetID.Text != "" && lbsheetID.Text != null)
                {
                    GetInfo(int.Parse(a), 2);//制单人信息
                }
                if (gvPayment.Rows.Count < 1)
                { Bind_Pay(); }

            }

            //应收
            //if (Session["EmpNo"] != null && Session["UserName"] != null)
            //    lb_Rec_linputEmpNum.Text = Session["UserName"].ToString();//制单人信息
            if (gvReceivables.Rows.Count > 1)
            { }
            else
            {
                if (((HiddenField)gvReceivables.Rows[0].FindControl("hfauditEmpID")).Value.Trim() != null && ((HiddenField)gvReceivables.Rows[0].FindControl("hfauditEmpID")).Value.Trim() != "0")
                {
                    //ddlreceivables.Visible = false;//当该单已被审核，则无需显示模板
                    //lbmuban.Visible = false;
                }
            }
            //应付
            //if (Session["EmpNo"] != null && Session["UserName"] != null)
            //    lb_Pay_linputEmpNum.Text = Session["UserName"].ToString();//制单人信息

            if (gvPayment.Rows.Count < 1)
            { }
            else
            {

                if (((HiddenField)gvPayment.Rows[0].FindControl("hfauditEmpID")).Value.Trim() != null && ((HiddenField)gvPayment.Rows[0].FindControl("hfauditEmpID")).Value.Trim() != "0")
                {
                    //ddlPayment.Visible = false;//当该单已被审核，则无需显示模板
                    //lbmuban.Visible = false;
                }



            }

            ShuiFei_Rec();
            ShuiFei_Pay();
            Change_Rec_money();
            Change_Pay_money();

            
        }
        /// <summary>
        /// 应收_绑定个空表--费用表
        /// </summary>
        protected void Bind_Rec()
        {

            DataTable dt1 = new DataTable("Table1");
            dt1.Columns.Add("编号", typeof(String));
            dt1.Columns.Add("feeTypeID", typeof(String));
            dt1.Columns.Add("sfeeAmount", typeof(String));
            dt1.Columns.Add("empID", typeof(String));
            dt1.Columns.Add("remark", typeof(String));
            dt1.Columns.Add("payedID", typeof(String));
            dt1.Columns.Add("auditEmpID", typeof(String));
            dt1.Columns.Add("afeeAmount", typeof(String));
            dt1.Columns.Add("invType", typeof(String));
            dt1.Columns.Add("invNO", typeof(String));
            dt1.Columns.Add("payType", typeof(String));
            dt1.Columns.Add("checkOut", typeof(String));
            //默认5行
            DataRow dr1 = dt1.NewRow();
            DataRow dr2 = dt1.NewRow();
            DataRow dr3 = dt1.NewRow();
            DataRow dr4 = dt1.NewRow();
            DataRow dr5 = dt1.NewRow();
            dr1[1] = "0";
            dr1[2] = "";
            dr1[3] = "";

            dr1[5] = "0";
            dr1[6] = "0";
            dr1[7] = "0";
            dr1[8] = "1";
            dr1[9] = "";
            dr1[10] = "2";
            dr1[11] = "1";


            dr2[1] = "0";
            dr2[2] = "";
            dr2[3] = "0";
            dr2[5] = "0";
            dr2[6] = "0";
            dr2[7] = "0";
            dr2[8] = "1";
            dr2[9] = "";
            dr2[10] = "2";
            dr2[11] = "1";

            dr3[1] = "0";
            dr3[2] = "";
            dr3[3] = "0";
            dr3[5] = "0";
            dr3[6] = "0";
            dr3[7] = "0";
            dr3[8] = "1";
            dr3[9] = "";
            dr3[10] = "2";
            dr3[11] = "1";

            dr4[1] = "0";
            dr4[2] = "";
            dr4[3] = "0";
            dr4[5] = "0";
            dr4[6] = "0";
            dr4[7] = "0";
            dr4[8] = "1";
            dr4[9] = "";
            dr4[10] = "2";
            dr4[11] = "1";

            dr5[1] = "0";
            dr5[2] = "";
            dr5[3] = "0";
            dr5[5] = "0";
            dr5[6] = "0";
            dr5[7] = "0";
            dr5[8] = "1";
            dr5[9] = "";
            dr5[10] = "2";
            dr5[11] = "1";
            dt1.Rows.Add(dr1);
            dt1.Rows.Add(dr2);
            dt1.Rows.Add(dr3);
            dt1.Rows.Add(dr4);
            dt1.Rows.Add(dr5);
            dt1.AcceptChanges();
            gvReceivables.DataSource = dt1;
            gvReceivables.DataBind();
        }
        /// <summary>
        /// 应付_绑定个空表
        /// </summary>
        protected void Bind_Pay()
        {

            DataTable dt1 = new DataTable("Table1");
            dt1.Columns.Add("编号", typeof(String));
            dt1.Columns.Add("feeTypeID", typeof(String));
            dt1.Columns.Add("sfeeAmount", typeof(String));
            dt1.Columns.Add("empID", typeof(String));
            dt1.Columns.Add("remark", typeof(String));
            dt1.Columns.Add("payedID", typeof(String));
            dt1.Columns.Add("auditEmpID", typeof(String));
            dt1.Columns.Add("afeeAmount", typeof(String));
            dt1.Columns.Add("invType", typeof(String));
            dt1.Columns.Add("invNO", typeof(String));
            dt1.Columns.Add("payType", typeof(String));
            dt1.Columns.Add("checkOut", typeof(String));

            //默认5行
            DataRow dr1 = dt1.NewRow();
            DataRow dr2 = dt1.NewRow();
            DataRow dr3 = dt1.NewRow();
            DataRow dr4 = dt1.NewRow();
            DataRow dr5 = dt1.NewRow();
            dr1[1] = "0";
            dr1[2] = "";
            dr1[3] = "0";
            dr1[5] = "0";
            dr1[6] = "0";
            dr1[7] = "0";
            dr1[8] = "1";
            dr1[9] = "";
            dr1[10] = "1";
            dr1[11] = "1";

            dr2[1] = "0";
            dr2[2] = "";
            dr2[3] = "0";
            dr2[5] = "0";
            dr2[6] = "0";
            dr2[7] = "0";
            dr2[8] = "1";
            dr2[9] = "";
            dr2[10] = "1";
            dr2[11] = "1";

            dr3[1] = "0";
            dr3[2] = "";
            dr3[3] = "0";
            dr3[5] = "0";
            dr3[6] = "0";
            dr3[7] = "0";
            dr3[8] = "1";
            dr3[9] = "";
            dr3[10] = "1";
            dr3[11] = "1";

            dr4[1] = "0";
            dr4[2] = "";
            dr4[3] = "0";
            dr4[5] = "0";
            dr4[6] = "0";
            dr4[7] = "0";
            dr4[8] = "1";
            dr4[9] = "";
            dr4[10] = "1";
            dr4[11] = "1";

            dr5[1] = "0";
            dr5[2] = "";
            dr5[3] = "0";
            dr5[5] = "0";
            dr5[6] = "0";
            dr5[7] = "0";
            dr5[8] = "1";
            dr5[9] = "";
            dr5[10] = "1";
            dr5[11] = "1";
            dt1.Rows.Add(dr1);
            dt1.Rows.Add(dr2);
            dt1.Rows.Add(dr3);
            dt1.Rows.Add(dr4);
            dt1.Rows.Add(dr5);
            dt1.AcceptChanges();
            gvPayment.DataSource = dt1;
            gvPayment.DataBind();
        }

        /// <summary>
        /// 应收_获取基础信息
        /// </summary>
        protected void infoBind_Rec()
        {
            int i = int.Parse(Session["sheetID"].ToString());
            CustomsSystem.Model.sheetInfo si = new CustomsSystem.BLL.SheetInfoManage().GetModel(i);

            if (si != null)
            {
                lbsheetID.Text = Session["sheetID"].ToString();
                lblCID.Text = Session["CustomerName"].ToString();
                lbladingBillNO.Text = si.ladingBillNo;
                lbagencyDate.Text = si.agencyDate.ToShortDateString();
                lbgoodsName.Text = si.goodsName;
                lbshipName.Text = si.shipName;
                lbJZXH.Text = si.containerNo;
                lbJZXL.Text = si.No;
                //lb_HWLX.Text = si.goodsType.ToString ();
                lb_BJH.Text = si.inspectionNo;
                lb_BGDH.Text = si.customsNo;
                //lb_LX.Text = si.typeID.ToString ();
                //lb_JCK.Text = si.inOut.ToString ();
                lbHTH.Text = si.contractNo;
                //lb_MYFS.Text = si.tradeType.ToString ();
                lb_WXP.Text = si.DangerousGoods.ToString ();
                if (si.DangerousGoods==true )
                {
                    lb_WXP.Text = "是";
                }
                if (si.DangerousGoods == false )
                {
                    lb_WXP.Text = "否";
                }
                if (si.inOut == 1)
                {
                    lb_JCK.Text = "转关进口";
                }
                if (si.inOut == 2)
                {
                    lb_JCK.Text = "转关出口";
                }

                if (si.inOut == 3)
                {
                    lb_JCK.Text = "形式进口";
                }
                if (si.typeID == 4)
                {
                    lb_LX.Text = "形式出口";
                }
                if (si.typeID == 1)
                {
                    lb_LX.Text = "报关";
                }
                if (si.typeID == 2)
                {
                    lb_LX.Text = "报检";
                }
                if (si.typeID == 3)
                {
                    lb_LX.Text = "报关报检";
                }
                if (si.tradeType == 1)
                {
                    lb_MYFS.Text = "一般类型";
                }
                if (si.tradeType == 2)
                {
                    lb_MYFS.Text = "进料加工";
                }
                if (si.tradeType == 3)
                {
                    lb_MYFS.Text = "来料加工";
                }
                if (si.goodsType == 1)
                {
                    lb_HWLX.Text = "集装箱";
                }
                if (si.goodsType == 2)
                {
                    lb_HWLX.Text = "木浆";
                }
                if (si.goodsType == 3)
                {
                    lb_HWLX.Text = "矿砂";
                }
                if (si.goodsType == 4)
                {
                    lb_HWLX.Text = "化工";
                }
                if (si.goodsType == 5)
                {
                    lb_HWLX.Text = "煤炭";
                }
                if (si.goodsType == 6)
                {
                    lb_HWLX.Text = "石油焦";
                }
                if (si.goodsType == 7)
                {
                    lb_HWLX.Text = "复合肥";
                }
                if (si.goodsType == 8)
                {
                    lb_HWLX.Text = "散货";
                }
                if (si.goodsType == 9)
                {
                    lb_HWLX.Text = "补报";
                }
                if (si.goodsType == 10)
                {
                    lb_HWLX.Text = "其他";
                }

            }

        }



        /// <summary>
        /// 应收_保存
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Rec_Save_Click(object sender, EventArgs e)
        {
            
            //验证费用是否同类
            for (int j = 0; j < gvReceivables.Rows.Count - 1; j++)
            {
                for (int n = 1; n < gvReceivables.Rows.Count; n++)
                {
                    if (((DropDownList)gvReceivables.Rows[j].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue == ((DropDownList)gvReceivables.Rows[n].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue && ((DropDownList)gvReceivables.Rows[j].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue != "0" && n != j)
                    {
                        
                     MessageBox.Show(this, "费用重复，请修改费用类别！");
                     return;
                    }
                }
            }
            CustomsSystem.Model.Bill bill = new CustomsSystem.Model.Bill();

            bill.auditEmpID = ((HiddenField)gvReceivables.Rows[0].FindControl("hfauditEmpID")).Value.Trim().ToString();
            //if (bill.auditEmpID != "0")
            //{
            //    Response.Write("<script>alert('该单已被审核，请反审核后再作修改');history.go(-2);</script>");

            //}
            //else
            //{
            string a = lbsheetID.Text;//要删除或者更新，先删除数据库里的数据，然后再保存
            BillManage bll = new BillManage();
            payBll.Delete(int.Parse(a), 1);
            bll.Delete(int.Parse(a), 1);
            
            //下面是保存gv的数据

            int cid; string sf;
            string cName;
            cName = lblCID.Text.Trim();
            CustomsSystem.Model.Customer cus = new CustomsSystem.BLL.CustomerManage().GetModel(cName);
            cid = cus.ID;

            for (int i = 0; i < gvReceivables.Rows.Count; i++)
            {
                bill.feeTypeID = ((DropDownList)gvReceivables.Rows[i].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue;//保存费用类别
                    
                if (bill.feeTypeID != "0")
                {
                    bill.sheetID = int.Parse(lbsheetID.Text.Trim());

                    bill.cID = cid;

                    bill.billTypeID = 1;
                        
                    sf = ((TextBox)gvReceivables.Rows[i].Cells[2].FindControl("tbfeeAmount")).Text;//保存金额
                    if (sf == "" || sf == null)
                        sf = "0";
                    bill.sfeeAmount = decimal.Parse(sf);

                    //bill.empID = ((DropDownList)gvReceivables.Rows[i].Cells[3].FindControl("ddlempID")).SelectedValue; ;
                    bill.inputDate = DateTime.Now;
                    bill.checkOut = int.Parse(((DropDownList)gvReceivables.Rows[i].Cells[3].FindControl("ddl_Rec_js")).SelectedValue);//保存结算方式
                    bill.invType = int.Parse(((DropDownList)gvReceivables.Rows[i].Cells[4].FindControl("DropDownList1")).SelectedValue);//保存发票类型
                    bill.invNO = ((TextBox)gvReceivables.Rows[i].Cells[4].FindControl("TextBox1")).Text;//保存发票号
                    bill.payType = int.Parse(((DropDownList)gvReceivables.Rows[i].Cells[4].FindControl("DropDownList2")).SelectedValue);//保存收费方式

                    bill.inputEmpNo = Session["EmpNo"].ToString();//保存录入员编号
                    // bill.inputEmpNo = Session["empNo"].ToString();
                    bill.remark = ((TextBox)gvReceivables.Rows[i].Cells[3].FindControl("tbremark")).Text.Trim().ToString();//保存备注
                    string AF = ((HiddenField)gvReceivables.Rows[i].FindControl("hfafeeAmount")).Value.ToString();
                    if (AF != null && AF != "")
                    { bill.afeeAmount = decimal.Parse(AF); }
                    else bill.afeeAmount = 0;
                    bill.empID = "0";

                    bill.auditEmpID = "0";
                    bill.payedID = 0;
                    bll.Add(bill);

                }
            }
            Response.Write("<script>alert('保存成功！');</script>");
            ShuiFei_Rec();
            audit_Rec();
            return;
        }


        /// <summary>
        /// 应收_获取费用类别
        /// </summary>
        /// <returns></returns>
        public DataTable GetFeeType()
        {
            FeeTypeManage feeTypeManage = new FeeTypeManage();
            DataSet ds = feeTypeManage.GetFeeList(" feeType =0 ");
            DataTable dt = ds.Tables[0];
            return dt;

        }
        /// <summary>
        /// 应收_获取人员表
        /// </summary>
        /// <returns></returns>
        public DataTable GetEmpNum()
        {
            CustomsSystem.BLL.UserManage UserManage = new UserManage();
            DataSet ds = UserManage.GetAllList();
            DataTable dt = ds.Tables[0];
            return dt;

        }



        /// <summary>
        /// 应收_获取已填入的数据
        /// </summary>
        /// <returns></returns>
        protected DataTable GetDataFromGrid_Rec()
        {
            DataTable dt1 = new DataTable("Table1");
            dt1.Columns.Add("编号");
            dt1.Columns.Add("feeTypeID");
            dt1.Columns.Add("sfeeAmount");
            dt1.Columns.Add("empID");
            dt1.Columns.Add("remark");
            dt1.Columns.Add("payedID", typeof(String));
            dt1.Columns.Add("auditEmpID", typeof(String));
            dt1.Columns.Add("afeeAmount", typeof(String));
            dt1.Columns.Add("invType", typeof(String));
            dt1.Columns.Add("invNO", typeof(String));
            dt1.Columns.Add("payType", typeof(String));
            dt1.Columns.Add("checkOut", typeof(String));
            for (int i = 0; i < gvReceivables.Rows.Count; i++)
            {
                GridViewRow gRow = gvReceivables.Rows[i];
                DataRow newRow = dt1.NewRow();
                newRow[0] = i + 1;
                newRow[1] = ((DropDownList)gRow.FindControl("ddlfeeTypeID")).SelectedValue;
                newRow[2] = ((TextBox)gRow.FindControl("tbfeeAmount")).Text;
                // newRow[3] = ((DropDownList)gRow.FindControl("ddlempID")).SelectedValue;
                newRow[4] = ((TextBox)gRow.FindControl("tbremark")).Text;
                newRow[5] = int.Parse(((HiddenField)gRow.FindControl("hfpayedID")).Value.ToString());
                newRow[6] = ((HiddenField)gRow.FindControl("hfauditEmpID")).Value;
                newRow[7] = decimal.Parse(((HiddenField)gRow.FindControl("hfafeeAmount")).Value.ToString());
                newRow[8] = ((DropDownList)gRow.FindControl("DropDownList1")).SelectedValue;
                newRow[9] = ((TextBox)gRow.FindControl("TextBox1")).Text;
                newRow[10] = ((DropDownList)gRow.FindControl("DropDownList2")).SelectedValue;
                newRow[11] = ((DropDownList)gRow.FindControl("ddl_Rec_js")).SelectedValue;
                dt1.Rows.Add(newRow);
                

            }
            dt1.AcceptChanges();

            return dt1;
        }
        /// <summary>
        /// 应收_增加一行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddRow_Click(object sender, EventArgs e)
        {

            DataTable dt = GetDataFromGrid_Rec();
            DataRow dr = dt.NewRow();

            dr[1] = "0";
            dr[2] = "";
            dr[3] = "0";
            dr[5] = "0";
            dr[6] = "0";
            dr[7] = "0";
            dr[8] = "1";
            dr[9] = "";
            dr[10] = "2";
            dr[11] = "1";

            dt.Rows.Add(dr);
            dt.AcceptChanges();
            gvReceivables.DataSource = dt;
            gvReceivables.DataBind();

        }

        /// <summary>
        /// 应收_获取审核人和制单人信息
        /// </summary>
        /// <param name="sheetID"></param>
        /// <param name="billTypeID"></param>
        public void GetInfo_Rec(int sheetID, int billTypeID)
        {
            BillManage bll = new BillManage();

            DataSet ds = bll.GetList(sheetID, billTypeID);

            gvReceivables.DataSource = ds;
            gvReceivables.DataBind();

            if (ds.Tables[0].Rows.Count > 1)
            {
                string empname = ds.Tables[0].Rows[0][7].ToString();
                string audit = ds.Tables[0].Rows[0][9].ToString();
                if (empname != null && empname != "")
                {
                    CustomsSystem.Model.Info_emp emp = new CustomsSystem.BLL.EmpManage().GetModel(empname);
                    if (emp != null)
                    {
                        //lb_Rec_linputEmpNum.Text = emp.UserName;
                    }
                }
                else
                {
                    if (Session["EmpNo"] != null && Session["UserName"] != null)
                    {
                        //lb_Rec_linputEmpNum.Text = Session["UserName"].ToString();
                    }
                }
                if (audit != null && audit != "")
                {
                    CustomsSystem.Model.Info_emp au = new CustomsSystem.BLL.EmpManage().GetModel(audit);
                    if (au != null)
                    {
                        //lb_Rec_audit.Text = "审核人：" + au.UserName;
                        //gvReceivables.Enabled = false;
                        //ddlreceivables.Enabled = false;
                        //btn_Rec_Save.Enabled = false;
                        //btn_Rec_audit.Enabled = false;
                        //btn_Rec_AddRow.Enabled = false;
                        ///Button4.Text = "反审核"; 
                    }
                    //else { lb_Rec_audit.Text = ""; btn_Rec_audit.Text = "审核"; }
                }
            }
        }
        /// <summary>
        /// 应收_隐藏列
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvReceivables_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // e.Row.Cells[3].Visible = false;//让第3列不可见
        }


        /// <summary>
        /// 应收_选择模板
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlTemplate_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (ddlreceivables.SelectedValue != "0")
            {
                Fee_templetdetailManage ftdm = new Fee_templetdetailManage();
                DataSet ds = ftdm.GetTList(" feetemplet_ID=" + ddlreceivables.SelectedValue);
                DataTable dt = ds.Tables[0];
                gvReceivables.DataSource = dt;
                gvReceivables.DataBind();
                Change_Rec_money();
            }

            
        }

        /// <summary>
        /// 应收_载入模板列表
        /// </summary>
        /// <returns></returns>
        public DataTable GetTemplate()
        {
            Session["billTypeID"] = "1";
            int i = int.Parse(Session["sheetID"].ToString());
            CustomsSystem.Model.sheetInfo sheet = new CustomsSystem.BLL.SheetInfoManage().GetModel(i);

            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            Fee_templetManage ftm = new Fee_templetManage();
            ds = ftm.GetList(" typeid=1 and goodsType=" + sheet.goodsType);
            dt = ds.Tables[0];
            return dt;
            
        }

        #region 新增的四个按钮
        /// <summary>
        /// 应收_审核或反审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void btn_Rec_audit_Click(object sender, EventArgs e)
        //{
        //    Session["billTypeID"] = "1";
        //    if (btn_Rec_audit.Text == "审核")
        //    {
        //        Bill model = new Bill();
        //        BillManage bll = new BillManage();
        //        model.billTypeID = int.Parse(Session["billTypeID"].ToString());
        //        model.sheetID = int.Parse(Session["sheetID"].ToString());
        //        model.auditEmpID = Session["EmpNo"].ToString();
        //        model.auditdate = DateTime.Today;
        //        if (bll.UpdateAudit(model))
        //            MessageBox.ShowAndRedirect(this, "审核成功", "cost.aspx");
        //        else
        //            MessageBox.ShowAndRedirect(this, "审核失败", "cost.aspx");
        //    }
        //    if (btn_Rec_audit.Text == "反审核")
        //    {
        //        Bill model = new Bill();
        //        BillManage bll = new BillManage();
        //        model.billTypeID = int.Parse(Session["billTypeID"].ToString());
        //        model.sheetID = int.Parse(Session["sheetID"].ToString());
        //        model.auditEmpID = "0";
        //        model.auditdate = DateTime.Today;
        //        if (bll.UpdateAudit(model))
        //            MessageBox.ShowAndRedirect(this, "反审核成功", "cost.aspx");
        //        else
        //            MessageBox.ShowAndRedirect(this, "反审核失败", "cost.aspx");
        //    }
        //}

        /// <summary>
        /// 应收_应付款录入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void Button1_Click(object sender, EventArgs e)
        //{
        //    Response.Redirect("payment.aspx");
        //}

        /// <summary>
        /// 应收_实收销账
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Rec_seff_Click(object sender, EventArgs e)
        {
            Response.Redirect("actualReceivables.aspx");
        }

        /// <summary>
        /// 应收_实付销账
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Rec_pay_Click(object sender, EventArgs e)
        {
            Response.Redirect("actualPayment.aspx");
        }
        #endregion
        // /// <summary>
        // /// 跳转到票结
        // /// </summary>
        // /// <param name="sender"></param>
        // /// <param name="e"></param>
        //protected void btnMakeE_Click(object sender, EventArgs e)
        //{
        //    Session["sheetID"] = int.Parse(lbsheetID .Text.Trim ());
        //    Response.Redirect("detailedAccount.aspx");
        //}
        /// <summary>
        /// 应付_获取基础信息
        /// </summary>
        protected void infoBind_Pay()
        {
            int i = int.Parse(Session["sheetID"].ToString());
            CustomsSystem.Model.sheetInfo si = new CustomsSystem.BLL.SheetInfoManage().GetModel(i);
            if (si != null)
            {
                lbsheetID.Text = Session["sheetID"].ToString();
                lblCID.Text = Session["CustomerName"].ToString();
                lbladingBillNO.Text = si.ladingBillNo;
                lbagencyDate.Text = si.agencyDate.ToShortDateString();
                lbgoodsName.Text = si.goodsName;
                lbshipName.Text = si.shipName;
            }
        }

        /// <summary>
        /// 应付_保存
        /// </summary>
        protected void btn_Pay_Save_Click(object sender, EventArgs e)
        {
            //验证费用是否同类
            for (int j = 0; j < gvPayment.Rows.Count - 1; j++)
            {
                for (int n = 1; n < gvPayment.Rows.Count; n++)
                {
                    if (((DropDownList)gvPayment.Rows[j].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue == ((DropDownList)gvPayment.Rows[n].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue && ((DropDownList)gvPayment.Rows[j].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue != "0" && n != j)
                    {
                        MessageBox.Show(this, "费用重复，请修改费用类别！");
                        return;
                     
                    }
                }
            }
            CustomsSystem.Model.Bill bill = new CustomsSystem.Model.Bill();
            bill.auditEmpID = ((HiddenField)gvPayment.Rows[0].FindControl("hfauditEmpID")).Value.Trim().ToString();
            //if (bill.auditEmpID != "0")
            //{
            //    Response.Write("<script>alert('该单已被审核，请反审核后再作修改');history.go(-2);</script>");
            //}
            //else
            //{
                string a = lbsheetID.Text;//要删除或者更新，先删除数据库里的数据，然后再保存
                BillManage bll = new BillManage();
                payBll.Delete(int.Parse(a), 2);
                bll.Delete(int.Parse(a), 2);



                //下面是保存gv的数据

                int cid; string sf;
                string cName;
                cName = lblCID.Text.Trim();
                CustomsSystem.Model.Customer cus = new CustomsSystem.BLL.CustomerManage().GetModel(cName);
                cid = cus.ID;

                for (int i = 0; i < gvPayment.Rows.Count; i++)
                {
                    bill.feeTypeID = ((DropDownList)gvPayment.Rows[i].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue;
                    if (bill.feeTypeID != "0")
                    {
                        
                        bill.sheetID = int.Parse(lbsheetID.Text.Trim());

                        bill.cID = cid;

                        bill.billTypeID = 2;

                        sf = ((TextBox)gvPayment.Rows[i].Cells[2].FindControl("tbfeeAmount")).Text;
                        if (sf == "" || sf == null)
                            sf = "0";
                        bill.sfeeAmount = decimal.Parse(sf);

                        bill.inputDate = DateTime.Now;
                        bill.inputEmpNo = Session["EmpNo"].ToString();
                        bill.invType = int.Parse(((DropDownList)gvPayment.Rows[i].Cells[1].FindControl("DropDownList3")).SelectedValue);//保存发票类型
                        bill.invNO = ((TextBox)gvPayment.Rows[i].Cells[4].FindControl("TextBox2")).Text;
                        bill.checkOut = int.Parse(((DropDownList)gvPayment.Rows[i].Cells[1].FindControl("ddl_Pay_js")).SelectedValue);//保存结算方式
                        bill.payType = int.Parse(((DropDownList)gvPayment.Rows[i].Cells[1].FindControl("DropDownList4")).SelectedValue);//保存付款方式

                        bill.remark = ((TextBox)gvPayment.Rows[i].Cells[3].FindControl("tbremark")).Text.Trim().ToString();
                        string AF = ((HiddenField)gvPayment.Rows[i].FindControl("hfafeeAmount")).Value.ToString();
                        if (AF != null && AF != "")
                        { bill.afeeAmount = decimal.Parse(AF); }
                        else bill.afeeAmount = null;
                        bill.auditEmpID = "0";
                        bill.payedID = 0;
                        bill.empID = "0";

                        bll.Add(bill);
                    }
                }
                Response.Write("<script>alert('保存成功！');</script>");
                ShuiFei_Pay();
                audit_Pay();
                return;
            //}
        
        }



        /// <summary>
        /// 应付_获取费用类别
        /// </summary>
        /// <returns></returns>

        public DataTable GetFeeType_Pay()
        {
            FeeTypeManage feeTypeManage = new FeeTypeManage();
            DataSet ds = feeTypeManage.GetFeeList(" feeType =0 ");
            DataTable dt = ds.Tables[0];
            return dt;

        }
        /// <summary>
        /// 应付_获取人员表
        /// </summary>
        /// <returns></returns>
        public DataTable GetEmpNum_Pay()
        {
            CustomsSystem.BLL.UserManage UserManage = new UserManage();
            DataSet ds = UserManage.GetAllList();
            DataTable dt = ds.Tables[0];
            return dt;

        }



        /// <summary>
        /// 应付_获取已填入的数据
        /// </summary>
        /// <returns></returns>
        protected DataTable GetDataFromGrid()
        {
            DataTable dt1 = new DataTable("Table1");
            dt1.Columns.Add("编号");
            dt1.Columns.Add("feeTypeID");
            dt1.Columns.Add("sfeeAmount");
            dt1.Columns.Add("empID");
            dt1.Columns.Add("remark");
            dt1.Columns.Add("payedID", typeof(String));
            dt1.Columns.Add("auditEmpID", typeof(String));
            dt1.Columns.Add("afeeAmount", typeof(String));
            dt1.Columns.Add("invType", typeof(String));
            dt1.Columns.Add("invNO", typeof(String));
            dt1.Columns.Add("payType", typeof(String));
            dt1.Columns.Add("checkOut", typeof(String));
            for (int i = 0; i < gvPayment.Rows.Count; i++)
            {
                GridViewRow gRow = gvPayment.Rows[i];
                DataRow newRow = dt1.NewRow();
                newRow[0] = i + 1;
                newRow[1] = ((DropDownList)gRow.FindControl("ddlfeeTypeID")).SelectedValue;
                newRow[2] = ((TextBox)gRow.FindControl("tbfeeAmount")).Text;
                //newRow[3] = ((DropDownList)gRow.FindControl("ddlempID")).SelectedValue;
                
                newRow[4] = ((TextBox)gRow.FindControl("tbremark")).Text;
                newRow[5] = int.Parse(((HiddenField)gRow.FindControl("hfpayedID")).Value.ToString());
                newRow[6] = ((HiddenField)gRow.FindControl("hfauditEmpID")).Value.ToString();
                newRow[8] = ((DropDownList)gRow.FindControl("DropDownList3")).SelectedValue;
                newRow[9] = ((TextBox)gRow.FindControl("TextBox2")).Text;
                newRow[10] = ((DropDownList)gRow.FindControl("DropDownList4")).SelectedValue;
                newRow[11] = ((DropDownList)gRow.FindControl("ddl_Pay_js")).SelectedValue;
                string AF = ((HiddenField)gRow.FindControl("hfafeeAmount")).Value.ToString();
                if (AF != null && AF != "")
                { newRow[7] = decimal.Parse(AF); }
                else newRow[7] = 0;

                dt1.Rows.Add(newRow);


            }
            dt1.AcceptChanges();

            return dt1;
        }
        /// <summary>
        /// 应付_增加一行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnAddRow_Pay_Click(object sender, EventArgs e)
        {
            addRow_pay();


        }
        protected void addRow_pay()
        {
            DataTable dt = GetDataFromGrid();
            DataRow dr = dt.NewRow();
            //dt.Rows.Add(dr);
            dr[1] = "0";
            dr[2] = "";
            dr[3] = "0";

            dr[5] = "0";
            dr[6] = "0";
            dr[7] = "0";
            dr[8] = "1";
            dr[9] = "";
            dr[10] = "1";
            dr[11] = "1";
            dt.Rows.Add(dr);
            dt.AcceptChanges();
            gvPayment.DataSource = dt;
            gvPayment.DataBind();
        }

        //应付显示审核人和制单人信息
        public void GetInfo(int sheetID, int billTypeID)
        {
            BillManage bll = new BillManage();

            DataSet ds = bll.GetList(sheetID, billTypeID);
            gvPayment.DataSource = ds;
            gvPayment.DataBind();
            //显示审核人和制单人信息
            if (ds.Tables[0].Rows.Count > 1)
            {
                string empname = ds.Tables[0].Rows[0][7].ToString();
                string audit = ds.Tables[0].Rows[0][9].ToString();
                if (empname != null && empname != "")
                {
                    CustomsSystem.Model.Info_emp emp = new CustomsSystem.BLL.EmpManage().GetModel(empname);
                    if (emp != null)
                    {
                        //lb_Pay_linputEmpNum.Text = emp.UserName;
                    }
                }
                else
                {
                    if (Session["EmpNo"] != null && Session["UserName"] != null)
                    {
                        //lb_Pay_linputEmpNum.Text = Session["UserName"].ToString();
                    }
                }
                if (audit != null && audit != "")
                {
                    CustomsSystem.Model.Info_emp au = new CustomsSystem.BLL.EmpManage().GetModel(audit);
                    if (au != null)
                    {
                        //lb_Pay_audit.Text = "审核人：" + au.UserName;
                        //gvPayment.Enabled = false;
                        //ddlPayment.Enabled = false;
                        //btn_Pay_Save.Enabled = false;
                        //btn_Pay_audit.Enabled = false;
                        //btn_Pay_AddRow.Enabled = false;
                        // Button4.Text = "反审核"; 
                    }
                    //else { lb_Pay_audit.Text = ""; btn_Pay_audit.Text = "审核"; }
                }
            }
        }


        /// <summary>
        /// 应付_载入模板列表
        /// </summary>
        /// <returns></returns>
        public DataTable GetTemplate_Pay()
        {
            int i = int.Parse(Session["sheetID"].ToString());
            CustomsSystem.Model.sheetInfo sheet = new CustomsSystem.BLL.SheetInfoManage().GetModel(i);

            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            Fee_templetManage ftm = new Fee_templetManage();
            ds = ftm.GetList(" typeid=2 and goodsType=" + sheet.goodsType);
            dt = ds.Tables[0];
            return dt;
            

        }
        /// <summary>
        /// 应付_选择模板
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void ddlTemplate_SelectedIndexChanged_Pay(object sender, EventArgs e)
        {
            if (ddlPayment.SelectedValue != "0")
            {
                Fee_templetdetailManage ftdm = new Fee_templetdetailManage();
                DataSet ds = ftdm.GetTList(" feetemplet_ID=" + ddlPayment.SelectedValue);
                DataTable dt = ds.Tables[0];
                gvPayment.DataSource = dt;
                gvPayment.DataBind();
                Change_Pay_money();
            }
        }
        #region 新增的四个按钮
        /// <summary>
        /// 应付_审核或反审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void btn_Pay_audit_Click(object sender, EventArgs e)
        //{
        //    Session["billTypeID"] = "2";
        //    if (btn_Pay_audit.Text == "审核")
        //    {
        //        Bill model = new Bill();
        //        BillManage bll = new BillManage();
        //        model.billTypeID = int.Parse(Session["billTypeID"].ToString());
        //        model.sheetID = int.Parse(Session["sheetID"].ToString());
        //        model.auditEmpID = Session["EmpNo"].ToString();
        //        model.auditdate = DateTime.Today;
        //        if (bll.UpdateAudit(model))
        //            MessageBox.ShowAndRedirect(this, "审核成功", "cost.aspx");
        //        else
        //            MessageBox.ShowAndRedirect(this, "审核失败", "cost.aspx");
        //    }
        //    if (btn_Pay_audit.Text == "反审核")
        //    {
        //        Bill model = new Bill();
        //        BillManage bll = new BillManage();
        //        model.billTypeID = int.Parse(Session["billTypeID"].ToString());
        //        model.sheetID = int.Parse(Session["sheetID"].ToString());
        //        model.auditEmpID = "0";
        //        model.auditdate = DateTime.Today;
        //        if (bll.UpdateAudit(model))
        //            MessageBox.ShowAndRedirect(this, "反审核成功", "cost.aspx");
        //        else
        //            MessageBox.ShowAndRedirect(this, "反审核失败", "cost.aspx");
        //    }
        //}

        /// <summary>
        /// 应付_应收款录入
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        //protected void Button1_Pay_Click(object sender, EventArgs e)
        //{
        //    Response.Redirect("receivables.aspx");
        //}

        /// <summary>
        /// 应付_实收销账
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Pay_sfee_Click(object sender, EventArgs e)
        {
            Response.Redirect("actualReceivables.aspx");
        }

        /// <summary>
        /// 应付_实付销账
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btn_Pay_pay_Click(object sender, EventArgs e)
        {
            Response.Redirect("actualPayment.aspx");
        }
        #endregion 




        protected void tbfeeAmount_TextChanged(object sender, EventArgs e)
        {

            Change_Pay_money();
        }

        protected void tbfeeAmount_TextChanged1(object sender, EventArgs e)
        {
            Change_Rec_money();

        }
        protected void Change_Rec_money()
        {
            //Decimal a = 0;
            //for (int i = 0; i < gvReceivables.Rows.Count; i++)
            //{
            //    if (((TextBox)gvReceivables.Rows[i].Cells[2].FindControl("tbfeeAmount")).Text != "")
            //    {
            //        a += Convert.ToDecimal(((TextBox)gvReceivables.Rows[i].Cells[3].FindControl("tbfeeAmount")).Text);
            //    }
            //}
            //lb_Rec_money.Text = "应收金额合计：" + a.ToString();
            Decimal a = Convert.ToDecimal(lb_Rec_Baopu.Text);
            Decimal b = Convert.ToDecimal(lb_Rec_Baozhuan.Text);
            Decimal c = Convert.ToDecimal(lb_Rec_Daipu.Text);
            Decimal d = Convert.ToDecimal(lb_Rec_Daizhuan.Text);
            Decimal f = a + b + c + d;
            lb_Rec_money.Text = f.ToString ();
        }
        protected void Change_Pay_money()
        {
            //Decimal a = 0;
            //for (int i = 0; i < gvPayment.Rows.Count; i++)
            //{
            //    if (((TextBox)gvPayment.Rows[i].Cells[2].FindControl("tbfeeAmount")).Text != "")
            //    {
            //        a += Convert.ToDecimal(((TextBox)gvPayment.Rows[i].Cells[2].FindControl("tbfeeAmount")).Text);
            //    }
            //}
            //lb_Pay_money.Text = "应付金额合计：" + a;
            Decimal a = Convert.ToDecimal(lb_Pay_Baopu.Text);
            Decimal b = Convert.ToDecimal(lb_Pay_Baozhuan.Text);
            Decimal c = Convert.ToDecimal(lb_Pay_Daipu.Text);
            Decimal d = Convert.ToDecimal(lb_Pay_Daizhuan.Text);
            Decimal f = a + b + c + d;
            lb_Pay_money.Text = f.ToString();

        }

        //转应付
        protected void gvReceivables_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "toPay")
            {
                int i = Convert.ToInt32(e.CommandArgument);
                
                for (int b = 0; b < gvPayment.Rows.Count ; b++)
                {
                        if (((DropDownList)gvPayment.Rows[b].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue == ((DropDownList)gvReceivables.Rows[i].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue && ((DropDownList)gvPayment.Rows[b].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue != "0" && ((DropDownList)gvReceivables.Rows[i].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue != "0")
                        {
                            if (((TextBox)gvPayment.Rows[b].Cells[2].FindControl("tbfeeAmount")).Text=="")
                            {
                                ((TextBox)gvPayment.Rows[b].Cells[2].FindControl("tbfeeAmount")).Text = "0";
                            }

                            ((TextBox)gvPayment.Rows[b].Cells[2].FindControl("tbfeeAmount")).Text = (Convert .ToDecimal  (((TextBox)gvPayment.Rows[b].Cells[2].FindControl("tbfeeAmount")).Text) + Convert .ToDecimal  (((TextBox)gvReceivables.Rows[i].Cells[2].FindControl("tbfeeAmount")).Text)).ToString ();
                            ((DropDownList)gvPayment.Rows[b].Cells[3].FindControl("ddl_Pay_js")).SelectedValue = ((DropDownList)gvReceivables.Rows[i].Cells[3].FindControl("ddl_Rec_js")).SelectedValue;
                            ((DropDownList)gvPayment.Rows[b].Cells[4].FindControl("DropDownList3")).SelectedValue  = ((DropDownList)gvReceivables.Rows[i].Cells[4].FindControl("DropDownList1")).SelectedValue ;
                            ((TextBox )gvPayment .Rows [b].Cells[5].FindControl ("TextBox2")).Text =((TextBox )gvReceivables .Rows [i].Cells [5].FindControl ("TextBox1")).Text ;
                            ((DropDownList)gvPayment.Rows[b].Cells[6].FindControl("DropDownList4")).SelectedValue = ((DropDownList)gvReceivables.Rows[i].Cells[6].FindControl("DropDownList2")).SelectedValue;
                            ((TextBox)gvPayment.Rows[b].Cells[7].FindControl("tbremark")).Text = ((TextBox)gvReceivables.Rows[i].Cells[7].FindControl("tbremark")).Text;
                            Change_Pay_money();
                            return;
                        }
                }
                addRow_pay();
                int j = gvPayment.Rows.Count;
                ((DropDownList)gvPayment.Rows[j - 1].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue = ((DropDownList)gvReceivables.Rows[i].Cells[1].FindControl("ddlfeeTypeID")).SelectedValue;
                ((TextBox)gvPayment.Rows[j - 1].Cells[2].FindControl("tbfeeAmount")).Text = ((TextBox)gvReceivables.Rows[i].Cells[2].FindControl("tbfeeAmount")).Text;
                ((DropDownList)gvPayment.Rows[j - 1].Cells[3].FindControl("ddl_Pay_js")).SelectedValue = ((DropDownList)gvReceivables.Rows[i].Cells [3].FindControl("ddl_Rec_js")).SelectedValue;
                ((DropDownList)gvPayment.Rows[j - 1].Cells[4].FindControl("DropDownList3")).SelectedValue = ((DropDownList)gvReceivables.Rows[i].Cells[4].FindControl("DropDownList1")).SelectedValue;
                ((TextBox)gvPayment.Rows[j - 1].Cells[5].FindControl("TextBox2")).Text = ((TextBox)gvReceivables.Rows[i].Cells[5].FindControl("TextBox1")).Text;
                ((DropDownList)gvPayment.Rows[j - 1].Cells[6].FindControl("DropDownList4")).SelectedValue = ((DropDownList)gvReceivables.Rows[i].Cells[6].FindControl("DropDownList2")).SelectedValue;
                ((TextBox)gvPayment.Rows[j - 1].Cells[7].FindControl("tbremark")).Text = ((TextBox)gvReceivables.Rows[i].Cells[7].FindControl("tbremark")).Text;
                Change_Pay_money();
                return;
            }
        }
        protected void ShuiFei_Rec()
        {
            lb_Rec_Baopu.Text = "0";
            lb_Rec_Baozhuan.Text = "0";
            lb_Rec_Daipu.Text = "0";
            lb_Rec_Daizhuan.Text = "0";
            Decimal a = 0;
            Decimal b = 0;
            Decimal c = 0;
            Decimal d = 0; 
            Decimal e = 0;
            Decimal f = 0;
            for (int i = 0; i < gvReceivables.Rows.Count; i++)
            {
                if (((TextBox)gvReceivables.Rows[i].Cells[2].FindControl("tbfeeAmount")).Text != "")
                {


                    if (((DropDownList)gvReceivables.Rows[i].Cells[3].FindControl("ddl_Rec_js")).SelectedValue == "1")
                    {
                        if (((DropDownList)gvReceivables.Rows[i].Cells[4].FindControl("DropDownList1")).SelectedValue == "1")
                        {


                            a += Convert.ToDecimal(((TextBox)gvReceivables.Rows[i].Cells[3].FindControl("tbfeeAmount")).Text);
                            b = a + a * Convert.ToDecimal(0.06);
                            lb_Rec_Baopu.Text = b.ToString();
                        }

                    }
                    if (((DropDownList)gvReceivables.Rows[i].Cells[3].FindControl("ddl_Rec_js")).SelectedValue == "2")
                    {
                        if (((DropDownList)gvReceivables.Rows[i].Cells[4].FindControl("DropDownList1")).SelectedValue == "1")
                        {

                            c += Convert.ToDecimal(((TextBox)gvReceivables.Rows[i].Cells[3].FindControl("tbfeeAmount")).Text);
                            d = c + c * Convert.ToDecimal(0.06);
                            lb_Rec_Daipu.Text = d.ToString();
                        }

                    }
                    if (((DropDownList)gvReceivables.Rows[i].Cells[3].FindControl("ddl_Rec_js")).SelectedValue == "1")
                    {
                        if (((DropDownList)gvReceivables.Rows[i].Cells[4].FindControl("DropDownList1")).SelectedValue == "2")
                        {

                            e += Convert.ToDecimal(((TextBox)gvReceivables.Rows[i].Cells[3].FindControl("tbfeeAmount")).Text);
                            lb_Rec_Baozhuan.Text = e.ToString();
                        }
                    }
                    if (((DropDownList)gvReceivables.Rows[i].Cells[3].FindControl("ddl_Rec_js")).SelectedValue == "2")
                    {
                        if (((DropDownList)gvReceivables.Rows[i].Cells[4].FindControl("DropDownList1")).SelectedValue == "2")
                        {

                            f += Convert.ToDecimal(((TextBox)gvReceivables.Rows[i].Cells[3].FindControl("tbfeeAmount")).Text);
                            lb_Rec_Daizhuan.Text = f.ToString();
                        }
                    }
                }
            }
        }
        protected void ShuiFei_Pay()
        {
            lb_Pay_Baopu.Text = "0";
            lb_Pay_Baozhuan.Text = "0";
            lb_Pay_Daipu.Text = "0";
            lb_Pay_Daizhuan.Text = "0";
            Decimal a = 0;
            Decimal b = 0;
            Decimal c = 0;
            Decimal d = 0;
            Decimal e = 0;
            Decimal f = 0;
            for (int i = 0; i < gvPayment .Rows .Count ; i++)
            {

                if (((TextBox)gvPayment.Rows[i].Cells[2].FindControl("tbfeeAmount")).Text != "")
                {

                    if (((DropDownList)gvPayment.Rows[i].Cells[3].FindControl("ddl_Pay_js")).SelectedValue == "1")
                    {
                        if (((DropDownList)gvPayment.Rows[i].Cells[4].FindControl("DropDownList3")).SelectedValue == "1")
                        {

                            a += Convert.ToDecimal(((TextBox)gvPayment.Rows[i].Cells[3].FindControl("tbfeeAmount")).Text);
                            b = a + a * Convert.ToDecimal(0.06);
                            lb_Pay_Baopu.Text = b.ToString();
                        }

                    }
                    if (((DropDownList)gvPayment.Rows[i].Cells[3].FindControl("ddl_Pay_js")).SelectedValue == "2")
                    {
                        if (((DropDownList)gvPayment.Rows[i].Cells[4].FindControl("DropDownList3")).SelectedValue == "1")
                        {

                            c+= Convert.ToDecimal(((TextBox)gvPayment.Rows[i].Cells[3].FindControl("tbfeeAmount")).Text);
                            d = c + c * Convert.ToDecimal(0.06);
                            lb_Pay_Daipu.Text = d.ToString();
                        }

                    }
                    if (((DropDownList)gvPayment.Rows[i].Cells[3].FindControl("ddl_Pay_js")).SelectedValue == "1")
                    {
                        if (((DropDownList)gvPayment.Rows[i].Cells[4].FindControl("DropDownList3")).SelectedValue == "2")
                        {

                            e += Convert.ToDecimal(((TextBox)gvPayment.Rows[i].Cells[3].FindControl("tbfeeAmount")).Text);
                            lb_Pay_Baozhuan.Text = e.ToString();
                        }
                    }
                    if (((DropDownList)gvPayment.Rows[i].Cells[3].FindControl("ddl_Pay_js")).SelectedValue == "2")
                    {
                        if (((DropDownList)gvPayment.Rows[i].Cells[4].FindControl("DropDownList3")).SelectedValue == "2")
                        {

                            f += Convert.ToDecimal(((TextBox)gvPayment.Rows[i].Cells[3].FindControl("tbfeeAmount")).Text);
                            lb_Pay_Daizhuan.Text = f.ToString();
                        }
                    }
                }
            }
        }
        protected void audit_Rec()
        {
                Session["billTypeID"] = "1";
                    Bill model = new Bill();
                    BillManage bll = new BillManage();
                    model.billTypeID = int.Parse(Session["billTypeID"].ToString());
                    model.sheetID = int.Parse(Session["sheetID"].ToString());
                    model.auditEmpID = Session["EmpNo"].ToString();
                    model.auditdate = DateTime.Today;
                    bll.UpdateAudit(model);
        }
        protected void audit_Pay()
        {
            Session["billTypeID"] = "2";
                Bill model = new Bill();
                BillManage bll = new BillManage();
                model.billTypeID = int.Parse(Session["billTypeID"].ToString());
                model.sheetID = int.Parse(Session["sheetID"].ToString());
                model.auditEmpID = Session["EmpNo"].ToString();
                model.auditdate = DateTime.Today;
            bll.UpdateAudit (model);
            
        }



    }
}